﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using Server.Model;
using System.Xml;

namespace Server.DB
{
    public class Context : DbContext
    {
        public Context() : base("Balder")
        {
        }

        public DbSet<Battery> Batteries { get; set; }
        public DbSet<BatteryType> BatteryTypes { get; set; }
        public DbSet<Car> Cars { get; set; }
        public DbSet<CarModel> CarModels { get; set; }
        public DbSet<PartReservation> PartReservations { get; set; }
        public DbSet<Reservation> Reservations { get; set; }
        public DbSet<Route> Routes { get; set; }
        public DbSet<Station> Stations { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<ZipCodeCity> ZipCodeCity { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //configure model with fluent API
            modelBuilder.Entity<Car>()
               .HasOptional(x => x.Battery)
               .WithOptionalPrincipal()
               .Map(x => x.MapKey("CarId"));

            modelBuilder.Entity<Battery>()
                .HasOptional(x => x.Car)
                .WithOptionalPrincipal()
                .Map(X => X.MapKey("BatteryId"));
        }
    }
}
